package com.dys.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @className: com.dys.controller.ExceptionController
 * @description: 处理当前Controller中的异常。
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/11/01 21:04
 */
@Controller
public class ExceptionController {

    @RequestMapping(value = "test1.action")
    public String test1() {
        int i = 1 / 0;
        return "forward:/ok.jsp";
    }

    @RequestMapping(value = "test2.action")
    public String test2() {
        String s1 = null;
        System.out.println(s1.length());
        return "forward:/ok.jsp";
    }

    @ExceptionHandler(value = {ArithmeticException.class, NullPointerException.class})
    public ModelAndView handelException() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("forward:/err.jsp");
        return mv;
    }
}
